﻿using System;



namespace LibraryETL
{
    internal class LibraryDIM
    {
        internal LibraryDIM(int fakultyKey, string libName)
        {
            FakultyKEY = fakultyKey;
            Name = libName;
        }

        internal readonly int FakultyKEY;
        internal readonly string Name;
    }

    internal class BookDIM
    {
        internal BookDIM(int naturalKey, string title, string author)
        {
            NaturalKEY = naturalKey;
            Title = title.Replace('\'', '`');
            Authors = author.Replace('\'', '`');
        }

        internal int NaturalKEY { get; private set; }
        internal int SurrogateKEY { get; set; }
        internal readonly string Title;
        internal string Authors { get; private set; }

        internal void AddAuthor(string author)
        {
            if(!String.IsNullOrEmpty(author))
                Authors += ", " + author.Replace('\'', '`');
        }
    }

    internal class TimeDIM
    {
        internal TimeDIM(DateTime time)
        {
            TimeKEY = String.Format("{0:yyyy-MM-dd-HH-mm-ss}", time);
            Date = String.Format("{0:dd.MM.yyyy}", time);
            DayTime = String.Format("{0:HH:mm:ss}", time);
        }

        internal readonly string TimeKEY;
        internal readonly string Date;
        internal readonly string DayTime;
    }



    internal class LibraryAccountDIM
    {
        internal LibraryAccountDIM(int studentKey, DateTime? creationTime, bool active)
        {
            StudentKEY = studentKey;
            CreationTimeKEY = creationTime!=null ? new TimeDIM(creationTime.Value).TimeKEY
                                                 : null;
            Active = active;
        }

        internal int StudentKEY;
        internal string CreationTimeKEY;
        internal bool Active;
    }

    internal class StudentDIM
    {
        internal StudentDIM(int naturalKey, string ais_id, string firstName, string lastName, int? grade, string fieldOfStudy)
        {
            NaturalKEY = naturalKey;
            AIS_id = int.Parse(ais_id);
            FirstName = firstName;
            LastName = lastName;
            Grade = grade;
            FieldOfStudy = fieldOfStudy;
        }

        internal int NaturalKEY { get; private set;}
        internal readonly int AIS_id;
        internal int SurrogateKEY { get; set; }
        internal int LibAccountSurrogateKEY { get; set; }
        internal readonly string FirstName;
        internal readonly string LastName;
        internal readonly int? Grade;             //"rocnik"
        internal readonly string FieldOfStudy;   //"studijny program"


        internal LibraryAccountDIM GetStudentLibraryAccount()
        {
            return new LibraryAccountDIM(SurrogateKEY, null, false);
            //Note: so far it returns NULL as creation time. In DWH core this should be set (ETL: SA -> ODS) to 
            //Note: student's beginning of study (as this is how it works on STU) and Active to TRUE only to running studies
        }
    }


    internal class BorrowingsFCT
    {
        internal BorrowingsFCT(int studentFK, int bookFK, string startTimeKey, string endTimeKEY)
        {
            StudentFK = studentFK;
            BookFK = bookFK;
            StartTimeKEY = startTimeKey;
            EndTimeKEY = endTimeKEY;
        }

        internal readonly int StudentFK;
        internal readonly int BookFK;
        internal readonly string StartTimeKEY;
        internal readonly string EndTimeKEY;

        internal int LibraryAccountSurrogateKEY { get; set; }
        internal int LibrarySurrogateKEY { get; set; }
        internal int BookSurrogateKEY { get; set; }
    }
}
